/*
 * FOF展示模块
 */
require('!style!css!../css/show.css');
var showHtml = require('!html!../html/show.html');
var common = require('./common.js');
var config = require('./config.js');
var page = require('./page.js');
var loading = require('./loading.js');
var showVue;
var show = {
    fofId: '',
    init: function (fofId) {
        fofId = fofId || 1;
        console.log('fofId:' + fofId);
        page.setPage(8);
        common.initNav(5);
        loading.start();
        $('.step').hide();
        $('#show').html(showHtml).show();
        show.fofId = fofId;
        this.showFofNav();
        this.showFofFundWeight();
        this.showFofAssetConf();
    },
    showFofNav: function () {
        page.initSelectedParams(8);
        var resetData = function (data, jsondata) {
            var bigJSON = {};
            var dataArray = [];
            var nameArray = [];
            $.each(data, function (k, v) {
                nameArray.push(v.name);
            });
            var findNavByDate = function (date) {
                var nav = 0;
                $.each(common.filterData(jsondata, 'fofNavList'), function (k, v) {
                    if (v.statisticDate == date) {
                        nav = v.swanav;
                        return false;
                    }
                });
                return nav;
            };
            $.each(data[0].priceList, function (k, v) {
                var childArray = [];
                childArray.push(v.date);
                childArray.push(findNavByDate(v.date));
                $.each(nameArray, function (kk, vv) {
                    childArray.push(data[kk].priceList[k].price);
                });
                dataArray.push(childArray);
            });
            bigJSON.dataArray = dataArray;
            nameArray = ('FOF组合,' + nameArray.join(',')).split(',');
            bigJSON.nameArray = nameArray;
            bigJSON.lineStyleObj = {
                'FOF组合': {
                    width: 3
                }
            };
            bigJSON.markLine = {
                data: [
                    {
                        name: 'FOF组合开始时间',
                        xAxis: jsondata.data.startDate,
                        symbol: 'none',
                        label: {
                            normal: {
                                show: false
                            }
                        },
                        lineStyle: {
                            normal: {
                                color: 'red',
                                type: 'solid'
                            }
                        },
                        tooltip: {
                            show: true,
                            formatter: '{b}'
                        }
                    }
                ]
            };
            return bigJSON;
        };
        window['getFofNavResult'] = function (json) {
            loading.end();
            console.log(json);
            var myChart = common.createECharts({
                json: json,
                bigJSONFunction: function (jsondata) {
                    return resetData(common.filterData(jsondata, 'fundList'), jsondata);
                },
                domId: 'fofNavECharts',
                text: 'FOF历史净值',
                precision: 4
            });
        };
        common.getData({
            path: 'getFofNav',
            callback: 'getFofNavResult',
            extra: '?fofId=' + show.fofId
        });
    },
    showFofFundWeight: function () {
        var resetData = function (data) {
            var bigJSON = {};
            var dataArray = [];
            var nameArray = [];
            $.each(data, function (k, v) {
                nameArray.push(k);
            });
            $.each(data[nameArray[0]], function (k, v) {
                var childArray = [];
                childArray.push(v.calcDate.split(' ')[0]);
                $.each(nameArray, function (kk, vv) {
                    childArray.push(data[vv][k].weight);
                });
                dataArray.push(childArray);
            });
            bigJSON.dataArray = dataArray;
            bigJSON.nameArray = nameArray;
            return bigJSON;
        };
        window['getFofWeightResult'] = function (json) {
            loading.end();
            console.log(json);
            if (JSON.stringify(json.data) == '{}' || JSON.stringify(json.data.fundCombList) == '{}') {
                return;
            }
            common.createECharts({
                json: json,
                bigJSONFunction: function (jsondata) {
                    return resetData(common.filterData(jsondata, 'fundCombList'));
                },
                domId: 'fofWeightECharts',
                text: '子基金权重变化图',
                precision: 4
            });
        };
        common.getData({
            path: 'getFofWeight',
            callback: 'getFofWeightResult',
            extra: '?fofId=' + show.fofId
        });
    },
    showFofAssetConf: function () {
        var resetData = function (data) {
            var bigJSON = {};
            var dataArray = [];
            var nameArray = [];
            $.each(data, function (k, v) {
                nameArray.push(k);
            });
            $.each(data[nameArray[0]], function (k, v) {
                var childArray = [];
                childArray.push(v.calcDate.split(' ')[0]);
                $.each(nameArray, function (kk, vv) {
                    childArray.push(data[vv][k].weight);
                });
                dataArray.push(childArray);
            });
            bigJSON.dataArray = dataArray;
            bigJSON.nameArray = nameArray;
            return bigJSON;
        };
        window['getFofAssetConfResult'] = function (json) {
            loading.end();
            console.log(json);
            if (JSON.stringify(json.data) == '{}' || JSON.stringify(json.data.fundCombList) == '{}') {
                return;
            }
            common.createECharts({
                json: json,
                bigJSONFunction: function (jsondata) {
                    return resetData(common.filterData(jsondata, 'fundCombList'));
                },
                domId: 'fofAssetConfECharts',
                text: '资产配置变化图',
                precision: 4
            });
        };
        common.getData({
            path: 'getFofAssetConf',
            callback: 'getFofAssetConfResult',
            extra: '?fofId=' + show.fofId
        });
    }
};
for (var key in show) {
    if (key) {
        exports[key] = show[key];
    }
}